import { http } from '@/utils/https'
import type { User } from '@/types/user'
import type { opneIdresult } from '@/types/login'

//普通登录
export const loginApi = (data: { phone: string; password: string }) => {
  return http<User>({
    url: '/login',
    method: 'POST',
    data,
  })
}
/**
 * 获取手机号
 */
export const getPhoneNumberApi = (code: string) => {
  return http<string>({
    url: '/slp/getPhoneNumber',
    method: 'POST',
    data: code,
  })
}
/**
 * 获取openid和昵称
 */
export const getOpenidAndNicknameApi = (code: string) => {
  return http<opneIdresult>({
    url: `/slp/getOpenIdAndNickName/${code}`,
    method: 'POST',
  })
}
/**
 *微信注册
 */
export const registerByWechatApi = (phone: string, openID: string, nickname: string = '') => {
  return http<User>({
    url: '/slp/registerByWeChat',
    method: 'POST',
    data: {
      phone: phone,
      openID: openID,
      nickname: nickname,
    },
  })
}
/**
 *微信登录
 */
export const loginByWechatApi = (openID: string) => {
  return http<User>({
    url: `/slp/loginByWeChat/${openID}`,
    method: 'POST',
  })
}

//普通注册
export const registerApi = (data: { phone: string; password: string }) => {
  return http<User>({
    url: '/register',
    method: 'POST',
    data,
  })
}
//发送验证码,直接发登录的码就行，没有注册的话会自动注册
export const sendCodeApi = (phone: string) => {
  return http({
    url: '/sendCode',
    method: 'POST',
    data: { phone, type: 1 },
  })
}
//验证码登录
export const loginByCodeApi = (data: { phone: string; code: string }) => {
  return http<User>({
    url: '/loginByCode',
    method: 'POST',
    data,
  })
}
